package com.kkb.kkbadmin.controller;


import com.kkb.kkbadmin.domain.Partner;
import com.kkb.kkbadmin.service.PartnerService;
import com.kkb.kkbcommon.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ${黄柯}
 * @title: Recommend
 * @projectName kkb-parent-v2
 * @description 后台对合作伙伴的操作
 * @since 2021-08-14
 */
@Api(tags = "首页合作伙伴管理")
@RestController
@RequestMapping("/home/partner")
public class PartnerController {

    @Autowired
    private PartnerService partnerService;


    /**
     * 后台列表显示合作伙伴的信息
     *
     * @return 返回要显示的合作伙伴数据信息
     */
    @ApiOperation("合作伙伴品牌数据信息的获取")
    @GetMapping("/list")
    public CommonResult<List<Partner>> findPartnerList() {
        List<Partner> result = partnerService.listAll();
        return CommonResult.success(result, "获取合作品牌方数据成功");
    }


    /**
     * 合作伙伴品牌的删除
     *
     * @param id:要删除的品牌id
     * @return 返回删除成功还是失败
     */
    @ApiOperation("合作伙伴品牌的删除")
    @ApiImplicitParam(name = "id", value = "根据传入的id删除合作伙伴品牌", dataType = "Long")
    @DeleteMapping("/deletePartner/{id}")
    public CommonResult deletePartnerById(@PathVariable("id") Long id) {
        partnerService.deletePartnerById(id);
        return CommonResult.success(null, "删除成功");
    }


    /**
     * 添加合作伙伴品牌
     *
     * @param partner:添加合作伙伴品牌的信息
     * @return 返回添加成功还是失败
     */
    @ApiOperation("添加合作伙伴品牌")
    @ApiImplicitParam(name = "partner", value = "添加合作伙伴品牌", dataType = "Partner")
    @PostMapping("/savePartner")
    public CommonResult addPartner(@Validated @RequestBody Partner partner) {
        partnerService.addPartner(partner);
        return CommonResult.success(null, "添加成功");
    }


    /**
     * 根据id更新合作伙伴的信息
     *
     * @param id:合作伙伴的id
     * @param partner：要修改的信息
     * @return 返回是否更新成功
     */
    @ApiOperation("根据id更新合作伙伴的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要更新的id", dataType = "Long"),
            @ApiImplicitParam(name = "partner", value = "要更新的信息", dataType = "partner")
    })
    @PutMapping("/editPartner/{id}")
    public CommonResult editPartnerById(@PathVariable("id") Long id,
                                        @Validated @RequestBody Partner partner) {
        partnerService.editPartnerById(id, partner);

        return CommonResult.success(null, "更新成功");

    }


}

